#!/usr/bin/env ruby

RBLOG_DIR = File.dirname(__FILE__)

require 'gtk2'
require 'rubygems'
require 'redcloth'

Dir.glob(File.join(RBLOG_DIR, './lib/*/*.rb')).each { |x| require x }

#include TrayIcon
include AboutWindow
include PostWindow
include GData

class TrayIcon
  def initialize
    puts "Starting tray icon."
    @tray_icon = Gtk::StatusIcon.new
    @tray_icon.set_icon_name('web-browser')
    @tray_icon.set_tooltip('rBlog Tray Icon')
    @tray_icon.signal_connect('popup-menu', &method(:on_right_click))
    @tray_icon.signal_connect('activate') { PostWindow::Post.new }
  end
  
  def on_right_click(status_icon, button, activate_time)
    puts "Right-click menu has been activated."
    
    right_click_menu = Gtk::Menu.new
    
    about = Gtk::ImageMenuItem.new('About')
    about_image = Gtk::Image.new(Gtk::Stock::ABOUT, Gtk::IconSize::MENU)
    about.set_image(about_image)
    about.signal_connect('activate') { About::About.new }
    about.show
    right_click_menu.append(about)
    
    exit = Gtk::ImageMenuItem.new('Quit')
    exit_image = Gtk::Image.new(Gtk::Stock::QUIT, Gtk::IconSize::MENU)
    exit.set_image(exit_image)
    exit.signal_connect('activate') { Quit.new }
    exit.show
    right_click_menu.append(exit)
    
    right_click_menu.show_all
    right_click_menu.popup(nil, nil, button, activate_time)
  end
end

  
class Quit
  def initialize
    puts "User has chosen to quit."
    Gtk.main_quit
  end
end

TrayIcon.new
Gtk.main
